const express = require('express');
const db = require('../../utils/db')

// 配置路由
const between_QR = express.Router();

between_QR.all('/between/huoqu', (req, res) => {
    const page = req.query.page;
    const count = req.query.count;
    const sql = `SELECT * FROM salary_between LIMIT ${(page - 1) * count},${count};`;
    const sql2=`SELECT COUNT(*) as total from salary_between;`;
    db.query(sql, function (err, data) {
        if (err) {
            res.send({ error: 1, msg: err })
        } else {
            // res.send({ error: 0, msg: '添加成功', data: data });
            db.query(sql2, (err2, data2) => {
                if (err2) {
                    console.log(err2)
                    res.send({ error: 1, msg: err2 })
                } else {
                    console.log(data2)
                    res.send({ error: 0, msg: '查询成功', data: data, total: data2[0].total })
                }
            })
        }
    })
});


// 删除
between_QR.post('/salary/shanchu', (req, res) => {
    const sql = 'delete from salary_between where b_id="' + req.body.id + '";';
    db.query(sql, (err, data) => {
        if (err) {
            console.log(err)
            res.send({ error: 1, msg: err })
        } else {
            res.send({ error: 0, msg: '删除成功' })
        }
    })
})



// 查询
between_QR.post('/between/chaxun1', (req, res) => {
    const sql = `SELECT * FROM salary_between WHERE b_Tid='${req.body.id}' OR b_name='${req.body.name}' OR b_wage='${req.body.wage}';`;
    db.query(sql, (err, data) => {
        if (err) {
            console.log(err)
            res.send({ error: 1, msg: err })
        }else {
            res.send({ error: 0, msg: '查询成功' ,data: data})
        }
    })
});

// 导出
module.exports = between_QR;